package cn.bookcycle.panda.pay.pojo;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.bookcycle.panda.pay.constant.BusinessData;
import cn.bookcycle.panda.pay.constant.NameData;
import cn.bookcycle.panda.pay.util.WechatUtil;


/**
 * 参数类
 * @author liufenglin
 * @date 2018年1月29日
 */
public class ParametersBase {
	private static final Logger logger = LoggerFactory.getLogger(ParametersBase.class);
	
	/**微信公众号ID或支付宝开发者的应用ID*/
	private String appId;	
	
	/**微信商户ID*/
	private String mchId;
	
	/**随机字符串*/
	private String nonceStr;
	
	/**签名*/
	private String sign;
	
	/**微信支付的交易类型*/
	private String tradeType;
	
	/**回调地址*/
	private String notifyUrl;
	
	public ParametersBase() {}
	
	/**
	 * 根据初始化appId、mchId、nonceStr、sign
	 * 
	 * @param map
	 */
	public ParametersBase(Map<String, Object> map) {
		this.appId = BusinessData.APP_ID_MAP.get(map.get(NameData.ACCOUNT));
		this.mchId = BusinessData.MCH_ID_MAP.get(map.get(NameData.ACCOUNT));
		this.nonceStr = WechatUtil.generateNonceStr();
		try {
			this.sign = WechatUtil.computeSign(map, nonceStr);
		} catch (UnsupportedEncodingException e) {
			logger.error("ParametersBase类调用sign签名错误！！！！！！");
		}
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public String getMchId() {
		return mchId;
	}

	public void setMchId(String mchId) {
		this.mchId = mchId;
	}

	public String getNonceStr() {
		return nonceStr;
	}

	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getTradeType() {
		return tradeType;
	}

	public void setTradeType(String tradeType) {
		this.tradeType = tradeType;
	}

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}

}
